﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OnATous
{
    public partial class Classement : System.Web.UI.Page
    {
        BusinessManagement.Rating ratingBM;
        BusinessManagement.User userBM;

        protected void Page_Load(object sender, EventArgs e)
        {
            ratingBM = new BusinessManagement.Rating();
            userBM = new BusinessManagement.User();

            Dictionary<Int64, float> marks = ratingBM.GetMarks();
            if (marks.Count != 0)
            {
                IEnumerable<KeyValuePair<Int64, float>> orderedmarks = marks.OrderByDescending(x => x.Value);

                DBO.User first = userBM.GetUserById(orderedmarks.First().Key);
                WinnerName.Text = first.FirstName + " " + first.LastName; // Nom et prénom du plus apprécié des contacts.
                WinnerNote.Text = orderedmarks.First().Value.ToString(); // Note du plus apprécié

                List<DBO.TmpUser> list = new List<DBO.TmpUser>();
                foreach (KeyValuePair<Int64, float> user in orderedmarks)
                {
                    DBO.User other = userBM.GetUserById(user.Key);
                    list.Add(new DBO.TmpUser(other.FirstName, other.LastName, other.Photo, user.Value.ToString(), ratingBM.GetNotationCount(other).ToString()));
                }

                NotesList.DataSource = list; // À classer par note, bien entendu
                NotesList.DataBind();
            }
        }

        
    }
}